'use strict';

const Controller = require('egg').Controller;
const jwt = require('jsonwebtoken');
class BaseController extends Controller {
  // 控制层返回前端数据成功统一处理
  async resData(res) {
    const { ctx, app } = this;
    ctx.status = res.httpState
    let resD = {
      data: res.data,
      msg: res.msg,
      code: res.code
    }
    if (res.path) {
      resD.token = await app.jwt.sign({ name: res.name, }, app.config.jwt.secret)
    }
    // console.log('\x1B[36m%s\x1B[0m', res)
    console.log('\x1B[36m%s\x1B[0m', resD)
    return resD;
  }
}
module.exports = BaseController;